<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>HTML在线编辑器</title>
<?php 
echo $javascript->link('editor/editor');
echo $html->css("editor/base");
?>
<script type="text/javascript">
//变量初始化
var guid = "1324481743";
var sState = "iframe";
var oContent="<div>&nbsp;</div>";
if(window.parent.document.getElementById(Request('id'))!=null){
var oInput=window.parent.document.getElementById(Request('id'));
var oForm=oInput.form;
oContent=oInput.value;
}else{
alert("编辑器id参数错误！");
}

//文章预览
function article_preview(){
var editor_win = window.open('', "_blank", '');
editor_win.document.open('text/html', 'replace');
editor_win.opener = null ;
editor_win.document.writeln($('editor_body_textarea').value);
editor_win.document.close();
}

//获得编辑器中的内容
function getHTML(){
if(editor_body_textarea.style.display=="none"){
   getHTML=EDiaryEditor.iframe.contentWindow.document.body.innerHTML;
}else{
   getHTML=$('editor_body_textarea').value;
}
return getHTML;
}

//表单提交函数
function AttachSubmit(){
oInput.value=getHTML();
EDiaryEditor.delEditorRsave();
}

//表单重置函数
function AttachReset(){
$('editor_body_textarea').value=oInput.value;
EDiaryEditor.iframe.contentWindow.document.body.innerHTML=oInput.value;
}

//附件提交和重置信息
if(document.attachEvent) oForm.attachEvent("onsubmit",AttachSubmit) ;
else oForm.addEventListener('submit',AttachSubmit,false);
    if (! oForm.submitEditor) oForm.submitEditor = new Array() ;
	oForm.submitEditor[oForm.submitEditor.length] = AttachSubmit ;
	if (! oForm.originalSubmit) {
		oForm.originalSubmit = oForm.submit ;
		oForm.submit = function() {
			if (this.submitEditor) {
				for (var i = 0 ; i < this.submitEditor.length ; i++) {
					this.submitEditor[i]() ;
				}
			}
			this.originalSubmit() ;
		}
	}
if(document.attachEvent) oForm.attachEvent("onreset",AttachReset);
else oForm.addEventListener('reset',AttachReset,false);
    if (! oForm.resetEditor) oForm.resetEditor = new Array() ;
	oForm.resetEditor[oForm.resetEditor.length] = AttachReset ;
	if (! oForm.originalReset) {
		oForm.originalReset = oForm.reset ;
		oForm.reset = function() {
			if (this.resetEditor) {
				for (var i = 0 ; i < this.resetEditor.length ; i++) {
					this.resetEditor[i]() ;
				}
			}
			this.originalReset() ;
		}
	}

//iframe框架自适应宽度和高度
function iframeAutoFit()
   {
      try
      {
         if(window!=parent)
         {
          var a = parent.document.getElementsByTagName("IFRAME");
            for(var i=0; i<a.length; i++)
            {
               if(a[i].contentWindow==window)
               {
                   var h = document.body.scrollHeight;
				   var w = document.body.scrollWidth;
                   a[i].style.height = h;
				   a[i].style.width = w;
               }
            }
         }
      }
      catch (ex)
      {
         alert("脚本无法跨域操作！");
      }
   }
if(document.attachEvent) window.attachEvent("onload",iframeAutoFit);  
else  window.addEventListener('load',iframeAutoFit,false); 
</script>
</head>
<body onConTextMenu="event.returnValue=false;">
<div id="editor_body" style="width:621px; height:457px;"></div>
</body>
</html>
<script type="text/javascript">
var et;

//自动保存历史开关
function readCookie(name)
{
var cookieValue = "";
var search = name + "=";
if(document.cookie.length > 0)
{ 
offset = document.cookie.indexOf(search);
if (offset != -1)
{ 
 offset += search.length;
 end = document.cookie.indexOf(";", offset);
 if (end == -1) end = document.cookie.length;
 cookieValue = unescape(document.cookie.substring(offset, end))
}
}
return cookieValue;
}

function writeCookie(name, value, hours)
{
var expire = "";
if(hours != null)
{
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();
}
document.cookie = name + "=" + escape(value) + expire + ";path=/";
}

function init() {
	writeCookie("EDiaryEditor_RSave", "true", 1);
	if(sState == "iframe"){
		EDiaryEditor.initialize("EDiaryEditor", "editor_body", true, oContent);
		et = EDiaryEditor;
	}else{
		EDiaryEditor.initialize("EDiaryEditor", "editor_body", true, "");
		et = EDiaryEditor;
	}
}
    if(window.Event)
        	window.onload = init;
	else
        	setTimeout(init, 100);
</script>
 
